package cn.tyoui.tool;

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class HDFSFile {

	private FileSystem fs ;
	private List<String> list=new ArrayList<>();

	public HDFSFile(String filePath) {
		try {
			fs = FileSystem.get(URI.create(filePath), new Configuration());
		} catch (IOException e) {
			e.printStackTrace();
		}
		allFile(new Path(filePath));
	}
	
	public void allFile(Path filePath) {
		try {
			FileStatus[] status = fs.listStatus(filePath);
			for (FileStatus file : status) {
				if (file.isDirectory()){
					list.add("----->"+file.getPath().toString().substring(25));
					allFile(file.getPath());
				}
				else
					list.add(file.getPath().toString().substring(25));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	
	public List<String> getList() {
		return list;
	}
}
